using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;

namespace CollegeShop.Infrastructure.Entities.Repository
{
    [Table("T_Issuedetail")]
    public class T_Issuedetail : IEntity<T_Issuedetail>
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int ID { get; set; }

        public int IssueID { get; set; }

        public int GoodsID { get; set; }

        public int IssueAmount { get; set; }

        public decimal IssuePrice { get; set; }

        public decimal IssueMoney { get; set; }

        public override T_Issuedetail Find(string key)
        {
            int id = Int32.Parse(key);
            return Find(c => c.ID == id);
        }

        public override T_Issuedetail Find(System.Linq.Expressions.Expression<Func<T_Issuedetail, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var item = ctx.Issuedetail.FirstOrDefault(where);
                if (item != null)
                {
                    this.ID = item.ID;
                    this.IssueID = item.IssueID;
                    this.GoodsID = item.GoodsID;
                    this.IssueAmount = item.IssueAmount;
                    this.IssuePrice = item.IssuePrice;
                    this.IssueMoney = item.IssueMoney;
                    return this;
                }
                return null;
            }
        }

        public override bool Any(System.Linq.Expressions.Expression<Func<T_Issuedetail, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.Issuedetail.Any(where);
            }
        }
    }
}
